package com.test;

/*
import java.util.Scanner;

public class Example01 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个三位数:");
        int number=sc.nextInt();
        int ge=number%10;
        int shi=number/10%10;
        int bai=number/100%10;
        System.out.println(ge+" "+shi+" "+bai);

    }
}
 */

/*
import java.util.Scanner;

// byte<short<int<long<float<double
public class Example01 {
    public static void main(String[] args) {
        //键盘录入2个整数
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入我们自己的一份时髦度:");
        int myFashion = sc.nextInt();
        System.out.println("请输入相亲对象衣服的时髦度:");
        int girlFashion = sc.nextInt();

        boolean result = myFashion > girlFashion;

        System.out.println(result);

    }
}


 */

/*
import java.util.Scanner;

public class Example01{
    public static void main(String[] args) {
        //1.获取两只老虎的体重
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一只老虎的体重");
        int weight1 = sc.nextInt();
        System.out.println("请输入第二只老虎的体重");
        int weight2 = sc.nextInt();

//2.利用三元运算符求出最终结果
        String result = weight1 == weight2 ? "相同" : "不相同";
        System.out.println(result);
    }
}

 */


/*
class A{
}

class Example01 {
    public static void main(String[] args){
        Class<?> c1 = null;			//声明Class对象c1
        Class<?> c2 = null;			//声明Class对象c2
        Class<?> c3 = null;			//声明Class对象c3
        try{
            c1 = Class.forName("com.test.A");//通过第（1）种方式实例化c1对象
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
        c2 = new A().getClass();			//通过第（2）种方式实例化c2对象
        c3 = A.class;						//通过第（3）种方式实例化c3对象
        System.out.println("类名称："+c1.getName());
        System.out.println("类名称："+c2.getName());
        System.out.println("类名称："+c3.getName());
    }
}

 */


/*
class Person {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "姓名:" + this.name + ",年龄:" + this.age;
    }
}

class Example02 {
    public static void main(String[] args) {
        Class<?> c = null;
        try {
            c = Class.forName("com.test.Person"); //调用forName()方法实例化c
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Person person = null;    //声明Person类对象person
        try {
            person = (Person) c.newInstance();   //
        } catch (Exception e) {
            e.printStackTrace();
        }
        person.setName("张三");
        person.setAge(20);
        System.out.println(person);
    }

}

 */

/*
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

class Person {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "姓名:" + this.name + ",年龄:" + this.age;
    }
}

class Example02 {
    public static void main(String[] args) {
        try {
            // 获取Person类的Class对象
            Class<?> c = Class.forName("com.test.Person");

            // 获取无参构造函数
            Constructor<?> constructor = c.getDeclaredConstructor();

            // 确保构造函数可访问
            constructor.setAccessible(true);

            // 使用构造函数创建Person类的实例
            Person person = (Person) constructor.newInstance();

            // 设置属性并打印对象
            person.setName("张三");
            person.setAge(20);
            System.out.println(person);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

 */


/*
import java.lang.reflect.Constructor;

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // getters and setters...

    @Override
    public String toString() {
        return "姓名：" + this.name + ",年龄：" + this.age;
    }
}

class Example01 {
    public static void main(String[] args) {
        Class<?> c = null;    // 声明Class对象c
        try {
            c = Class.forName("com.test.Person");     // 实例化对象c
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return; // 如果找不到类，则退出程序
        }

        Constructor<?> cons[] = null;      // 声明Constructor类对象数组cons
        try {
            cons = c.getDeclaredConstructors(); // 使用getDeclaredConstructors来获取所有构造方法，包括非公共的
            // 如果需要公共构造方法，使用c.getConstructors();
        } catch (Exception e) {
            e.printStackTrace();
            return; // 如果找不到构造方法，则退出程序
        }

        Person person1 = null;
        Person person2 = null;

        try {
            // 假设Person类有一个接受String和int参数的构造方法
            Constructor<?> constructor = cons[0]; // 获取第一个构造方法，这里假设它是正确的构造方法
            constructor.setAccessible(true); // 如果构造方法不是public的，设置为可访问
            person1 = (Person) constructor.newInstance("张三", 30); // 实例化第一个Person对象

            // 通常情况下，你不会同时有两个接受相同参数的构造方法，因此这里仅创建一个人
            // 如果Person类确实有多个构造方法，并且你想使用另一个，你需要确保选择正确的构造方法

        } catch (Exception e) {
            e.printStackTrace();
        }

        // 如果需要创建第二个对象，确保使用不同的变量，并且确保构造方法可用

        System.out.println(person1); // 打印第一个人的信息
        // System.out.println(person2); // 如果创建了第二个人，可以打印第二个人的信息
    }
}

 */

/*
interface China{
    public static final String NATION = "China";
    public static final String AUTHOR = "张三";
}
class Person implements China{
    private String name;
    private int age;
    public Person(String name, int age){
        this.setName(name);
        this.setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "姓名:" + this.name + ",年龄:" + this.age;
    }
}

public class Example01 {
    public static void main(String[] args) {
        Class<?> c=null;
        try{
            c=Class.forName("com.test.Person");
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
        Class<?> cons[]=c.getInterfaces();
        for(int i=0; i<cons.length; i++){
            System.out.println("实现的接口名称：" + cons[i].getName());
        }
    }
}


 */


/*
class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.setName(name);
        this.setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "姓名:" + this.name + ",年龄:" + this.age;
    }
}

public class Example01 {
    public static void main(String[] args) {
        Class<?> c1 = null;         //声明Class类的对象
        try {
            c1 = Class.forName("com.test.Person");      //实例化Class类的对象
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Class<?> c2 = c1.getSuperclass();      //获取Person类的父类
        System.out.println("父类名称:" + c2.getName());
    }
}


 */

/*
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

class Person {
    private String name;
    private int age;

    public Person() {
    }                        //无参构造方法

    public Person(String name) {            //有一个参数的构造方法
        this.name = name;
    }

    public Person(String name, int age) {    //有两个参数的构造方法
        this.setName(name);
        this.setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "姓名：" + this.name + ",年龄：" + this.age;
    }
}

public class Example01 {
    public static void main(String[] args) {
        Class<?> c1 = null;
        try {
            c1 = Class.forName("com.test.Person");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //获取全部构造方法,存储到Constructors类数组con中
        Constructor<?> con[] = c1.getConstructors();
        for (int i = 0; i < con.length; i++) {   //循环打印构造方法信息
            //获取构造方法详细信息并输出
            Class<?> p[] = con[i].getParameterTypes();
            System.out.print("构造方法:");
            System.out.print(con[i].getModifiers()+" ");  //获取构造方法权限
            int mo = con[i].getModifiers();
            System.out.print(Modifier.toString(mo) + " ");
            System.out.print(con[i].getName() + " ");   //获取构造方法名称
            System.out.print(" (");
            for (int j = 0; j < p.length; j++) {
                //打印构造方法参数信息
                System.out.print(p[j].getName() + " arg" + i);
                if (j < p.length - 1){
                    System.out.print(",");
                }
            }
            System.out.println("){}");
        }
    }
}

 */



